package com.minglead.crawler.enums;

import cn.hutool.core.util.ObjectUtil;
import com.minglead.crawler.entity.SelectEntity;
import com.minglead.crawler.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author bxh
 * @Description 舆情情感
 * @date 2024/8/1
 */
public enum SentimentEnum {
    //情感，0:正面，1:负面，2:中性(64以内);
    POSITIVE("0", "正面"),
    NEGATIVE("1", "负面"),
    NEUTRAL("2", "中性");


    /** 枚举值 */
    private final String code;

    /** 枚举描述 */
    private final String description;


    SentimentEnum(String code, String message) {
        this.code = code;
        this.description = message;
    }

    public String getCode() {
        return code;
    }

    public String getMessage() {
        return description;
    }

    /**
     * 获取下拉列表填充数据
     * @return 下拉列表填充数据
     */
    public static List<SelectEntity> getSelectList() {
        List<SelectEntity> result = new ArrayList<>();
        for (SentimentEnum row :
                SentimentEnum.values()) {
            SelectEntity data = new SelectEntity();
            data.setLabel(row.description);
            data.setVal(row.code);
            result.add(data);
        }
        return result;
    }

    public static SentimentEnum getEnum(String code) {
        if (ObjectUtil.isNotNull(code)) {
            SentimentEnum[] VALUES = SentimentEnum.values();
            for (SentimentEnum ele : VALUES) {
                if (StringUtils.equals(ele.code,code)) {
                    return ele;
                }
            }
        }
        return null;
    }
}
